package com.vf.admin.client.controller.trip;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.dto.AppTripDto;
import com.vf.admin.client.service.AppTripCommentService;
import com.vf.admin.client.service.AppTripService;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppTrip;
import com.vf.admin.miaodong.entity.AppTripComment;
import com.vf.admin.miaodong.entity.AppTripFriend;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/10/19 10:44
 */
@RestController
@RequestMapping("/app/newTrip")
public class AppTripController extends ClientBaseController {


    @Resource
    private AppTripService appTripService;
    @Resource
    private AppTripCommentService appTripCommentService;


    @ResponseBody
    @RequestMapping("/listTrip")
    public Result list(Integer pageno) {

        SplitPageBean splitPageBean = new SplitPageBean(pageno, 20);

        HashMap<String, Object> params = new HashMap<>();
        List<AppTripDto> list = appTripService.getAppTripDtoPage(params, splitPageBean);
        return this.sucessPage(list, splitPageBean.getNextPageNo());
    }

    @ResponseBody
    @RequestMapping("/listTripComment")
    public Result listTripComment(Integer tripId) {


        List<AppTripComment> listAppTripComment = appTripCommentService.getListAppTripComment(tripId);
        return this.sucessJSON(listAppTripComment);
    }

    /**
     * 发布
     */
    @RequestMapping("/save")
    @ResponseBody
    public Result save(AppTripParam param) {

        //
        AppTrip appTrip =new AppTrip();
        BeanUtil.copyProperties(param,appTrip);
        appTrip.setCreatetime(new Date());
        appTrip.setScore("4.6");
        appTripService.save(appTrip);

        return this.sucessJSON(null);
    }
}
